home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_sharity.idb / etc / init.d / fw_sharity.z / fw_sharity
Text File  |  2002-07-08  |  5KB  |  184 lines

  1. #!/bin/sh
  2. # Name: sharity.init
  3. # Project: Sharity
  4. # Author: Christian Starkjohann <cs@obdev.at>
  5. # Creation Date: 1998-08-15
  6. #
  7. # Modified by Stephane Rosa <srosa@domusmea.org> for SGI Irix
  8. # September 2001 srosa/SGI
  9. #
  10. # Tabsize: 4
  11. # Copyright: (c) 1999 by Christian Starkjohann, all rights reserved.
  12. #     For details of the license see the file doc/License.txt.
  13. # This Revision: $Id: sharity.init,v 1.20 2002/05/06 15:06:13 cs Exp $
  14.  
  15. # RedHat information for the chkconfig/ntsysv tools:
  16. # chkconfig: 2345 65 20
  17. # description: Sharity is a client for the Microsoft networking protocol CIFS.
  18.  
  19. # General Description:
  20. # This script starts or stops the sharityd daemon. It is suitable to be
  21. # called from a startup directory. For most systems it is sufficient to
  22. # make a link from this file into the startup directory.
  23. #
  24. # Arguments:
  25. #   start       start the daemon
  26. #   stop        shutdown the daemon
  27. #
  28. # If called with no arguments, the daemon is started.
  29.  
  30. SHARITY=/usr/freeware
  31. SERVER=${SHARITY}/sbin/sharityd
  32. CLIENT=${SHARITY}/bin/sharity
  33. PIDFILE=${SHARITY}/var/sharity.pid
  34. MOUNTDIR=${SHARITY}/var/mount
  35. COREDIR=${SHARITY}/var
  36. CONFIG=${SHARITY}/etc/sharity.cfg
  37. IS_ON=/etc/chkconfig
  38.  
  39. nicevalue="-5"
  40.  
  41. if $IS_ON verbose
  42. then
  43.     ECHO="/bin/echo"
  44. else
  45.     ECHO=":"
  46. fi
  47.  
  48. if test $# -ne 0; then
  49.     what=$1
  50. else
  51.     what=start
  52. fi
  53.  
  54.  
  55. whereis()
  56. {
  57.     echo $PATH | tr ':' '\012' | {
  58.         while read path; do
  59.             if [ -x "$path/$1" ]; then
  60.                 echo "$path/$1"
  61.                 break
  62.             fi
  63.         done
  64.     }
  65. }
  66.  
  67. # We need to detect HP-UX because renice needs the '-n' flag there.
  68. # We can't use uname directly because it does not exist on all platforms.
  69. # The same seems to be true for the IRIX 6.x 'renice' command.
  70. uname="`whereis uname`"
  71. renice=renice
  72. renicep="-p"
  73. if [ -n "$uname" ]; then
  74.     osname="`$uname -s`"
  75.     if [ "$osname" = HP-UX ]; then
  76.         renice="renice -n"
  77.     fi
  78.     if [ "$osname" = AIX ]; then
  79.         renice="renice -n"
  80.         renicep=""
  81.     fi
  82.     if [ "$osname" = IRIX ]; then
  83.         if expr match "`$uname -r`" '6[.].*' >/dev/null; then
  84.             renice="renice -n"
  85.         fi
  86.     fi
  87. fi
  88.  
  89. isRunning()
  90. {
  91.     if test -f $PIDFILE; then
  92.         # check whether process with this PID is running. Use renice and not
  93.         # kill -0 to introduce no additional incompatibilities.
  94.         pid=`cat $PIDFILE`
  95.         if $renice +0 $renicep "$pid" >/dev/null 2>&1; then
  96.             # process with pid exists -- make sure it's a sharityd
  97.             psline1=`ps -p "$pid" 2>/dev/null`
  98.             psline2=`ps "$pid" 2>/dev/null`    # other variant if -p fails
  99.             psline=`echo "$psline1" "$psline2" | grep sharityd`
  100.             if [ -n "$psline" ]; then
  101.                 echo "yes"
  102.             fi
  103.         fi
  104.     fi
  105. }
  106.  
  107. case "$what" in
  108.   start)
  109.     if ! $IS_ON fw_sharity; then
  110.         exit 0
  111.     fi
  112.     $ECHO "Starting Sharity daemon:"
  113.     if [ "`isRunning`" = yes ]; then
  114.         $ECHO "Error starting: there is already an instance of the daemon running!"
  115.         $ECHO "Please stop the running daemon before you start a new one."
  116.         exit 1
  117.     fi
  118.     if [ ! -d "$MOUNTDIR" ]; then
  119.         mkdir -p "$MOUNTDIR"
  120.     fi
  121.     # delete stale automount directories:
  122.     for i in "$MOUNTDIR"/*; do
  123.         if [ -d "$i" ]; then
  124.             rmdir "$i";
  125.         fi
  126.     done
  127.     cd "$COREDIR"    # create corefiles here
  128.     if [ -f "core" ]; then
  129.         mv core core.backup
  130.         mail root << EOF
  131. Dear System Administrator,
  132. this is a mail from your Sharity software. The Sharity daemon has
  133. crashed and dumped core, sorry about that. Please help us (Objective
  134. Development) to find this bug! We need the core file, which has been
  135. backed up to ${COREDIR}/core.backup
  136. and we need your sharityd executable, which can be found at
  137. ${SERVER}. Please compress both files
  138. into an archive and mail it to <sharity-bugs@obdev.at>. Since core-files
  139. and executables tend to be LARGE files, please get in contact with us
  140. BEFORE you mail us the files; the bug may already be known or even fixed
  141. in a newer release!
  142.  
  143. Security Note: core files may contain private data such as the content
  144. of your files or your passwords. Please be aware of this fact when you
  145. mail the core file.
  146.  
  147. Regards,
  148. your Sharity software.
  149. EOF
  150.     fi
  151.     "${SERVER}" -f "${CONFIG}"
  152.     sleep 1             # wait until pid-file is created
  153.     $renice $nicevalue $renicep "`cat $PIDFILE`"
  154.     $ECHO "done."
  155.     ;;
  156.   start_msg)
  157.     $ECHO "Starting Sharity daemon:"
  158.     ;;
  159.   stop)
  160.     $ECHO "Shutting down Sharity daemon: "
  161.     if [ "`isRunning`" = yes ]; then
  162.         $ECHO "unmounting... "
  163.         if "$CLIENT" umount -a -f; then
  164.             kill "`cat $PIDFILE`"
  165.             $ECHO "done."
  166.         else
  167.             $ECHO "Error unmounting, daemon not stopped."
  168.         fi
  169.     else
  170.         $ECHO "Daemon not running!"
  171.     fi
  172.     ;;
  173.   stop_msg)
  174.     $ECHO "Shutting down Sharity daemon: "
  175.     ;;
  176.   reload)
  177.     $ECHO "Reloading not required for Sharity."
  178.     ;;
  179.   *)
  180.     $ECHO "Usage: $0 {start|stop}"
  181.     exit 1
  182.     ;;
  183. esac
  184.